﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WcfBackend;

public partial class PopupChooseAllergies : System.Web.UI.Page
{
    private static WcfFoodAndAllergiesClient wcf;
    List<Allergies> Returnlist = new List<Allergies>();

    protected void Page_Load(object sender, EventArgs e)
    {
        wcf = new WcfFoodAndAllergiesClient();

        List<Allergies> extingAllergies = wcf.SelectAllAllergies().ToList();

        foreach (Allergies item in extingAllergies)
        {
            ExtingAllergies.Items.Add(item.Name);
        }

        Session.Clear();
        //ExtingAllergies.DataSource = extingAllergies;
        //ExtingAllergies.DataBind();
    }
    //public List<Allergies>returnAllergies()
    //{
        
    //}
    protected void MoveLeft_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ExtingAllergies.Items)
        {
            if (item.Selected == true)
            {
                ChoosenAllergies.Items.Remove(item);
            }
        }

        
    }
    protected void MoveRight_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ExtingAllergies.Items)
        {
            if (item.Selected == true)
            {
                if (!ChoosenAllergies.Items.Contains(item))
                {
                    ChoosenAllergies.Items.Add(item);
                }
                

            }
        }    
    }
    protected void Done_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in ChoosenAllergies.Items)
        {

            try
            {
                Returnlist.Add(wcf.GetAllergies(item.Text));
            }
            catch (Exception)
            {
                
                throw;
            }
            
           

        }
        Session["AllergiList"] = Returnlist;
        Response.Redirect("RecipeSearch.aspx");
    }
}